# Maintainer:
pkgname=musikcube
pkgver=3.0.2
pkgrel=1
pkgdesc="a cross-platform, terminal-based music player, audio engine, metadata indexer, and server"
url="https://github.com/clangen/musikcube"
arch="all"
license="BSD-3-Clause"
# TODO: libbasu-dev instead of elogind-dev yields a nonfunctioning mpris plugin,
# even though session is not in elogind anyway, libelogind works
makedepends="
	alsa-lib-dev
	asio-dev
	cmake
	curl-dev
	elogind-dev
	ffmpeg-dev
	kissfft-dev
	lame-dev
	libev-dev
	libmicrohttpd-dev
	libopenmpt-dev
	ncurses-dev
	pipewire-dev
	samurai
	sdbus-cpp-dev
	sqlite-dev
	taglib-dev
	"
# TODO: split server (-d)
# put plugins in not /usr/share
# split locales
subpackages="
	$pkgname-dev
	$pkgname-plugin-all:allplugins
	"
source="$pkgname-$pkgver.tar.gz::https://github.com/clangen/musikcube/archive/refs/tags/$pkgver.tar.gz
	locale.patch
	tinfo.patch
	sys.patch
	"
options="!check" # no tests

# alsa/pipewire/ffmpegdecorder left in by default
_plugins="
	httpdatastream
	mpris
	openmpt
	server
	stockencoders
	supereqdsp
	taglibreader
	"
for _plugin in $_plugins; do
	subpackages="$subpackages $pkgname-plugin-$_plugin:plugin"
done

prepare() {
	default_prepare

	cd src/3rdparty
	rm -r src/sqlite
	rm -r src/kiss*
}

build() {
	# no-ncursesw prevents looking in the wrong place
	# disable-update-check is passed for ''homebrew builds'', removes update checker
	CFLAGS="$CFLAGS -DNDEBUG -O2" \
	CXXFLAGS="$CXXFLAGS -DDISABLE_UPDATE_CHECK -DNO_NCURSESW -DNDEBUG -O2" \
	cmake -B build -G Ninja \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DCMAKE_BUILD_TYPE=None
	cmake --build build
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	mkdir -p "$pkgdir"/usr/lib
	mv "$pkgdir"/usr/share/musikcube/libmusikcore.so "$pkgdir"/usr/lib/

	# just sh wrappers, so use symlinks instead
	ln -sfv ../share/musikcube/musikcube "$pkgdir"/usr/bin/musikcube
	ln -sfv ../share/musikcube/musikcubed "$pkgdir"/usr/bin/musikcubed
}

plugin() {
	local sub="${subpkgname#"$pkgname"-plugin-}"
	pkgdesc="$pkgdesc ($sub plugin)"

	amove usr/share/musikcube/plugins/*$sub*.so
}

allplugins() {
	pkgdesc="$pkgdesc (all plugins)"
	local plugin
	for plugin in $_plugins; do
		depends="$depends $pkgname-plugin-$plugin=$pkgver-r$pkgrel"
	done
	mkdir -p "$subpkgdir"
}

sha512sums="
33d7fa0768c235afa2d877fb2bd3523f47c2fcf1bd500daabbd3755645439c51a1d477e8e8fe7f2a6aba451121b0d600e413fa0a491da9947a4dff7cb0430d82  musikcube-3.0.2.tar.gz
cbb0c515a245475221f98b6858152f99c5e0d1d95ee4d79ecfcb616788f907099aed7195fa16180267900e56c136bd9d38caea7b285a2f8720cd7a767cbba279  locale.patch
4f473fae6a4351875930ee5ba537116047e7cd1e16d70822f815b46bacb4e80289afcef9c577b0ef9c966ddc8087819391a2517b630e4ef4a791c120b849b2a7  tinfo.patch
fdcd4c2ed2771b6c5584723a6a9e7d4ab582cceb5f50f4b8bd22b59be31eb8bf905c4e5981c6aabcf437ff64ea5b49b0b0ec2b8da5b458311a8880bdacbc8be5  sys.patch
"
